
#pragma once
#include <string>
#include <curl/curl.h>
#include "HttpHeader.hpp"

namespace CppWinApi::HttpClients
{
    // http 响应
    class HttpResponse
    {
    private:
        CURLcode code;
        std::string data;

    public:
        HttpResponse(CURLcode code, std::string &data)
        {
            this->code = code;
            this->data = data;
        }
        CURLcode GetCode() { return code; }
        std::string &GetData() { return data; }
    };

    enum class HttpMethod
    {
#undef DELETE
#undef GET
#undef POST
#undef PUT
        GET,
        POST,
        PUT,
        DELETE
    };

    // http 客户端
    class HttpClient
    {
    private:
        CURL *curl;
        static size_t OnReceive(char *ptr, size_t size, size_t nmemb, void *userdata);
        void SetHttpMethod(HttpMethod method);

    public:
        HttpClient();
        ~HttpClient();
        HttpHeader httpHeader;
        HttpResponse Request(const std::string url, HttpMethod method, std::string body = "");
        HttpResponse Post(const std::string url, const std::string body);
        HttpResponse Get(const std::string url);
    };
}